package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController {
    //依赖注入
    @Autowired
    private OrderService orderService;
    @Autowired
    private HttpSession session;

    //生成订单信息
    @RequestMapping("/submit")
    public R<String> addOrder(@RequestBody Orders orders) {
        //获取会话中的用户id
        Long id = (Long) session.getAttribute("user");
        //调用业务层的生成订单的方法,添加订单信息
        orderService.addOrder(orders, id);
        //返回结果
        return R.success("下单成功");
    }
}
